import time, string

# 当前的时间戳
timeStamp_now = round(time.time())
print(timeStamp_now)

# 时间戳转换格式化时间字符串
inputTime = 1554173914
expectTimestamp = time.strftime('%y/%m/%d %H:%M:%S', time.localtime(timeStamp_now))

# print(expectTimestamp)
new_expectTimestamp = expectTimestamp.replace('/', '').replace(':', '')
# print(new_expectTimestamp)

# 格式化化时间字符串转换成时间戳(1.格式化的时间字符串转换成时间元组 2.时间元组转换成时间戳)
inputStr = '190402 105834'

expectTime = round(time.mktime(time.strptime(new_expectTimestamp, '%y%m%d %H%M%S')))
# print(expectTime)


# 时间戳转化为格式化时间
def transferto_formattime(timestamp, timeformat='%y/%m/%d %H:%M:%S'):
    return time.strftime(timeformat, time.localtime(timestamp))


print(transferto_formattime(1554174913))



# 格式化时间转换为时间戳
def transferto_timestamp(formattime, timeformat='%y%m%d %H%M%S'):
    if '-' and ':' in formattime:
        new_formattime = formattime.replace('-', '').replace(':', '')

    time_tuple = time.strptime(new_formattime, timeformat)
    return round(time.mktime(time_tuple))

str = '19-05-23 11:34:39'

print(transferto_timestamp(str))

